﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.ObjectModel;
using System.Threading;
using System.Windows;
using System.Windows.Resources;
using System.IO;

namespace TaxLawView
{
    public static class Service
    {
        public static ObservableCollection<Category> GetCategories(Category parent)
        {
            Thread.Sleep(1000);
            ObservableCollection<Category> result = new ObservableCollection<Category>();
            if (parent == null)
            {
                //TODO:获得第一级分类
                result.Add(new Category { Name = "税法" });
            }
            else
            {
                //TODO:获得子分类
                if (parent.Depth < 2)
                {
                    for (int i = 0; i < 5; i++)
                    {
                        Category child = new Category();
                        child.Depth = parent.Depth + 1;
                        child.Name = string.Format("{0}-{1}", parent.Name, i);
                        result.Add(child);
                    }
                }
            }
            return result;
        }

        public static ObservableCollection<Law> GetLaws(Category category)
        {
            ObservableCollection<Law> laws = new ObservableCollection<Law>();
            for (int i = 0; i < 100; i++)
            {
                laws.Add(new Law { ID = i.ToString(), Name = string.Format("{0}, name{1}", category.Name, i) });
            }
            return laws;
        }

        public static string GetLawContent(Law law)
        {
            if (law == null)
                return null;
            StreamResourceInfo sri = Application.GetResourceStream(new Uri("/TaxLawView.Model;component/law.html", UriKind.RelativeOrAbsolute));
            using (StreamReader sr = new StreamReader(sri.Stream, Encoding.Unicode))
            {
                string str = sr.ReadToEnd();
                return str;
            }
        }
    }
}
